﻿using System.Linq;
using NazTek.Documenter.Ssis.Control.Tasks;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

namespace NazTek.Documenter.Ssis.Control
{
    internal static class Utility
    {
        internal static AccessMode GetAccessMode(IDTSComponentMetaData100 component)
        {
            return (AccessMode) GetCustomProperty(component, "AccessMode").Value;
        }
        internal static string GetCustomPropertyValue(IDTSComponentMetaData100 component, string propertyName)
        {
            var prop = GetCustomProperty(component, propertyName);
            return prop == null ? "Unavailable" : prop.Value;
        }
        internal static IDTSCustomProperty100 GetCustomProperty(IDTSComponentMetaData100 component, string propertyName)
        {
            return component.CustomPropertyCollection
                .Cast<IDTSCustomProperty100>().FirstOrDefault(p => p.Name == propertyName);
        }
    }
}